/*
 * Copyright 2012 Faculty of Informatics - Masaryk University.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package cz.muni.fi.pa165.creatures.dto.mapping;

import cz.muni.fi.pa165.creatures.dto.CreatureTypeWeaponDTO;
import cz.muni.fi.pa165.creatures.dto.mapping.api.MappingDTO;
import cz.muni.fi.pa165.creatures.model.CreatureTypeWeapon;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * This class represents the mapping between
 * {@link cz.muni.fi.pa165.creatures.model.CreatureTypeWeapon} and
 * {@link cz.muni.fi.pa165.creatures.dto.CreatureTypeWeaponDTO} and vice versa.
 *
 * @author smikloso
 */
public class CreatureTypeWeaponMapping implements MappingDTO<CreatureTypeWeaponDTO, CreatureTypeWeapon> {

    @Autowired
    private CreatureTypeMapping creatureTypeMapping;
    
    @Autowired
    private WeaponMapping weaponMapping;

    @Override
    public CreatureTypeWeaponDTO entityToDTO(CreatureTypeWeapon entity) {
        CreatureTypeWeaponDTO dto = new CreatureTypeWeaponDTO();
        dto.setCreatureDTO(creatureTypeMapping.entityToDTO(entity.getCreatureType()));
        dto.setWeaponDTO(weaponMapping.entityToDTO(entity.getWeapon()));
        dto.setEfficiency(entity.getEffectivity().toString());
        return dto;
    }

    @Override
    public CreatureTypeWeapon DTOtoEntity(CreatureTypeWeaponDTO dto) {
        CreatureTypeWeapon entity = new CreatureTypeWeapon();
        entity.setCreatureType(creatureTypeMapping.DTOtoEntity(dto.getCreatureDTO()));
        entity.setWeapon(weaponMapping.DTOtoEntity(dto.getWeaponDTO()));
        entity.setEffectivity(Float.parseFloat(dto.getEfficiency()));
        return entity;
    }
}
